package branch

import (
	"io/ioutil"
	"fmt"
)

func main() {
	const filename = "abc.txt"
	contents, err := ioutil.ReadFile(filename)
	if err != nil{
		fmt.Println(err)
	}
	fmt.Printf("%s\n", contents)
	fmt.Println("--------line-----------")
	
	
	if contents, err = ioutil.ReadFile(filename); err != nil{ //contents, err 的作用域只在这个if block里
		fmt.Println(err)
	} else {
		fmt.Printf("%s\n", contents)
	}
	fmt.Println("--------line-----------")
	
	
	fmt.Println(
		grade(10),
		grade(60),
		grade(78),
		//grade(-78),
		grade(89),
		grade(98),
		grade(100),
		//grade(110),
	)
	
	
}

func grade(score int) string {
	g := ""
	switch {
	case score < 0 || score > 100:
		panic(fmt.Sprintf("Wrong score: %d", score))
	case score < 60:
		g = "F"
	case score < 80:
		g = "C"
	case score < 90:
		g = "B"
	case score <= 100:
		g = "A"
	}
	return g
}
